//wcb :时间计算函数
// 如果事件在据现在1分钟内返回刚刚
// 1分钟到1小时内返回多少分钟前
// 1小时到24小时内返回多少小时前
// 超过一天返回具体时间

// timeFormatter.js
export const formatTime = (time) => {
    const now = new Date();
    const timestamp = new Date(time);
    const diff = now - timestamp;

    const minute = 60 * 1000;
    const hour = 60 * minute;
    const day = 24 * hour;

    if (diff < minute) {
        return '刚刚';
    } else if (diff < hour) {
        const minutesAgo = Math.floor(diff / minute);
        return `${minutesAgo}分钟前`;
    } else if (diff < day) {
        const hoursAgo = Math.floor(diff / hour);
        return `${hoursAgo}小时前`;
    } else {
        const year = timestamp.getFullYear();
        const month = timestamp.getMonth() + 1;
        const day = timestamp.getDate();
        const hour = timestamp.getHours();
        const minute = timestamp.getMinutes();
        return `${year}-${month}-${day} ${hour}:${minute}`;
    }
};